package com.xywy.broadcast;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;
import android.util.Log;

import com.xywy.R;
import com.xywy.find.RemindListActivity;

public class RemindBroadCast extends BroadcastReceiver {
	public static final String REMINDACTION = "REMINDBROADCAST"; // 發送的提醒廣播
	private Vibrator vibrator;
	static int count = 0;
	
	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		if (REMINDACTION.equals(intent.getAction())) {
			Log.e("RemindBroadCast", "提醒了----");
            String message = intent.getStringExtra("message");
			NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

			Notification n = new Notification(R.drawable.ic_launcher, message,
					System.currentTimeMillis());

			n.flags = Notification.FLAG_AUTO_CANCEL;
			Intent i = new Intent(context, RemindListActivity.class);

			i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
					| Intent.FLAG_ACTIVITY_NEW_TASK);

			// PendingIntent

			PendingIntent contentIntent = PendingIntent.getActivity(

			context,

			R.string.app_name,

			i,

			PendingIntent.FLAG_UPDATE_CURRENT);

			n.setLatestEventInfo(

			context,

			"寻医问药",

			message,

			contentIntent);
			count++;
			nm.notify(count, n);
			
			 vibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);  
		        long [] pattern = {15000,400,15000,400};   // 停止 开启 停止 开启   
//		        vibrator.vibrate(pattern,-1);    
		        vibrator.vibrate(5000);  //重复两次上面的pattern 如果只想震动一次，index设为-1   
		}
	}

}
